package com.suxin.netty.remoting;

import com.alibaba.fastjson.JSON;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author Tang
 * @classname RemotingJsonSerializable
 * @description [  ]
 * @date 2022/12/11 18:14
 */
public class RemotingJsonSerializable {

    public static byte[] encode(final Object o) {
        return JSON
                .toJSONString(o, false)
                .getBytes(StandardCharsets.UTF_8);
    }

    public static RemotingCommand decoder(byte[] headerData, Class<RemotingCommand> remotingCommandClass) {
        return JSON.parseObject(new String(headerData, Charset.defaultCharset()),remotingCommandClass);
    }
}
